// FIT_6204_Gorodilov_TrSegDoc.h : interface of the CFIT_6204_Gorodilov_TrSegDoc class
//


#pragma once

#include "FIT_6204_Gorodilov_Rect.h"
#include "FIT_6204_Gorodilov_TreeElement.h"

class CFIT_6204_Gorodilov_TrSegDoc : public CDocument
{
protected: // create from serialization only
	CFIT_6204_Gorodilov_TrSegDoc();
	DECLARE_DYNCREATE(CFIT_6204_Gorodilov_TrSegDoc)

// Attributes
public:

// Operations
public:

// Overrides
public:
	virtual BOOL OnNewDocument();
	virtual void Serialize(CArchive& ar);
	const CSize GetScrollSize(void) const;

// Implementation
public:
	virtual ~CFIT_6204_Gorodilov_TrSegDoc();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions
protected:
	DECLARE_MESSAGE_MAP()

public:
	CArray<CFIT_6204_Gorodilov_Rect>	m_aRects;
	CArray<CFIT_6204_Gorodilov_Point>	m_aBoundVert;
	CArray<CFIT_6204_Gorodilov_Point>	m_aBoundHor;
	bool	m_bIsFirstPoint;

private:	
	CSize m_sScrollSize;
public:
	bool Run(void);
	void generateTree(CFIT_6204_Gorodilov_TreeElement* v);
	void deleteTree(CFIT_6204_Gorodilov_TreeElement* v);
	void AddSegment(CFIT_6204_Gorodilov_TreeElement* v, CFIT_6204_Gorodilov_Point& point, int direction);
	void RemoveSegment(CFIT_6204_Gorodilov_TreeElement* v, CFIT_6204_Gorodilov_Point& point);
	void Contribution(CFIT_6204_Gorodilov_TreeElement* v, CFIT_6204_Gorodilov_Point& point, 
		CList<CFIT_6204_Gorodilov_Point> *stack);
};

CString GetNextLine(CArchive &ar);
int comparePoints(const void *arg1, const void *arg2);

int comparePoints2(const void *arg1, const void *arg2);
